package com.sunrise.xdoc.entity.order;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import com.sunrise.xdoc.entity.AbstractAuditEntity;
import com.sunrise.xdoc.entity.catalog.SanPham;

@Entity
@Table(name = "order_chi_tiet_don_hang")
@Inheritance(strategy = InheritanceType.JOINED)
public class ChiTietDonHang extends AbstractAuditEntity {
	private static final long serialVersionUID = 1L;
	private SanPham sanPham;
	private DonHang donHang;
	private int soLuong;
	private Long donGia; // don gia luc ban hang

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "san_pham_id")
	@NotNull
	public SanPham getSanPham() {
		return sanPham;
	}

	public void setSanPham(SanPham sanPham) {
		this.sanPham = sanPham;
	}

	@ManyToOne(fetch = FetchType.EAGER, optional = false)
	@JoinColumn(name = "don_hang_id")
	@NotNull
	public DonHang getDonHang() {
		return donHang;
	}

	public void setDonHang(DonHang donHang) {
		this.donHang = donHang;
	}

	@Column(name = "so_luong")
	@Max(value = 9999, message = "Số lượng không được lớn hơn 9999")
	@Min(value = 0, message = "Số lượng không được nhỏ hơn 0")
	public int getSoLuong() {
		return soLuong;
	}

	public void setSoLuong(int soLuong) {
		this.soLuong = soLuong;
	}

	@Column(name = "don_gia")
	public Long getDonGia() {
		return donGia;
	}

	public void setDonGia(Long donGia) {
		this.donGia = donGia;
	}
}
